using System;
using System.Collections.Generic;
using System.Text;

namespace NNFramework.NeuroLibrary
{
    /// <summary>
    /// Class that holds activation functions
    /// </summary>
    public static class clsActivationFunctions
    {
        /// <summary>
        /// Pass Function
        /// </summary>
        /// <param name="pdblFx">The value to use int the calc</param>
        /// <returns>If pdblFx >= 1 then 1, else 0</returns>
        public static int PassFunction(double pdblFx)
        {
            if (pdblFx >= 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }

        /// <summary>
        /// Adaline Activation Function
        /// </summary>
        /// <param name="pdblFx">The value to use in the calc</param>
        /// <returns>If pdblFx > 1 return 1, if pdblFx &lt1 then -1,else returns pdblFx</returns>
        public static double AdalineFunction(double pdblFx)
        {
            if (pdblFx > 1)
            {
                return 1;
            }
            else
            {
                if (pdblFx < -1)
                {
                    return -1;                    
                }
                else
                {
                    return pdblFx;
                }
            }
        }

        /// <summary>
        /// Function that activates a neuron at 0, returns 1 over the umbral else returns -1 
        /// </summary>
        /// <param name="pdblFx">Value to Evaluate the Activation</param>
        /// <returns>1 when pdblFx is 0 or above, else -1</returns>
        public static int StairFunction(double pdblFx)
        {
            return pdblFx >= 0 ? 1 : -1;
        }

        /// <summary>
        /// Function that returns the function value 
        /// </summary>
        /// <param name="pdblFx">Value to Evaluate the Activation</param>
        /// <returns>The pdblFx integer value</returns>
        public static int IdentityFunction(double pdblFx)
        {   
            return Convert.ToInt32(pdblFx);
        }

        /// <summary>
        /// Function that returns the function value 
        /// </summary>
        /// <param name="pdblFx">Value to Evaluate the Activation</param>
        /// <returns>The pdblFx integer value</returns>
        public static double IdentityFunctionDouble(double pdblFx)
        {
            return pdblFx;
        }

        /// <summary>
        /// Step Activation Function
        /// </summary>
        /// <param name="pdblFx">The value to use int the calc</param>
        /// <returns>If pdblFx >= 0 then 0, else 1</returns>
        public static int StepFunction(double pdblFx)
        {
            return pdblFx <= 0 ? 0 : 1;
        }
    }    
}
